def compare_files(file1, file2):
    print("Comparing files:", file1, "and", file2)
    with open(file1, 'r') as f1, open(file2, 'r') as f2:
        lines1 = f1.readlines()
        lines2 = f2.readlines()
    if len(lines1) != len(lines2):
        print("Files have different number of lines.")
        return
    err=[]
    for i, (line1, line2) in enumerate(zip(lines1, lines2)):
        cols1 = line1.strip().split(',')[0].split()
        cols2 = line2.strip().split(',')[0].split()
        if len(cols1) != len(cols2):
            print(f"Line {i+1}: Files have different number of columns.")
            continue
        for j, (col1, col2) in enumerate(zip(cols1, cols2)):
            if col1 != col2 :
                err.append(abs(float(col1)-float(col2)))  # 比较时忽略空白字符
    if not err :
        print("totally equal")
        return 1
    print(f'there are {len(err)} errs, and max is {max(err)}')
                


name='fc3'
compare_files(f'result_py/{name}.txt', f'result_cu/{name}.txt')